<?php

namespace app\admin\model;

use think\Model;


class IdentityInfo extends Model
{
    private $c_sql = "CREATE TABLE `fa_identity_info` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) DEFAULT NULL COMMENT '用户id',
  `identity_type` varchar(255) DEFAULT '' COMMENT '身份',
  `school` varchar(255) DEFAULT '' COMMENT '学校名称',
  `name` varchar(255) DEFAULT '' COMMENT '姓名',
  `phone` varchar(100) DEFAULT '' COMMENT '电话',
  `club_one_id` int(10) DEFAULT NULL COMMENT '社团id',
  `club_two_id` int(10) DEFAULT NULL COMMENT '子社团id',
  `hourly_rate` decimal(11,1) DEFAULT NULL COMMENT '课时费用',
  `appointment_time_week` varchar(255) DEFAULT '' COMMENT '可约时间（周）',
  `appointment_time` varchar(255) DEFAULT '' COMMENT '可约时间（时）',
  `teacher_certification` text COMMENT '教师资格证',
  `diploma` text COMMENT '毕业证书',
  `occupational_qualifications` text COMMENT '获奖证书',
  `course_outline` text COMMENT '课程大纲',
  `teaching_objectives` text COMMENT '教学目标',
  `knowledge_requirements` text COMMENT '预备知识要求',
  `imgs` text COMMENT '形象照',
  `addtime` datetime DEFAULT NULL COMMENT '添加时间',
  `sort` int(10) DEFAULT NULL COMMENT '排序',
  `tag` varchar(100) DEFAULT NULL COMMENT '标签',
  `score` decimal(6,1) DEFAULT '10.0' COMMENT '评分',
  `user_score` varchar(255) DEFAULT '' COMMENT '用户评分',
  `people` int(10) DEFAULT '0' COMMENT '人数',
  `personal_resume` text COMMENT '个人简历',
  `professional_skill` text COMMENT '专业技能证书',
  `health_certificate` text COMMENT '健康证',
  `identity_card_img` varchar(500) DEFAULT NULL COMMENT '身份证复印件',
  `no_crime` text COMMENT '无犯罪证明',
  `area` varchar(255) DEFAULT '' COMMENT '区域',
  `is_all` varchar(255) DEFAULT '否' COMMENT '是否上传完整',
  `educational_back` text COMMENT '教育背景',
  `work_experience` text COMMENT '工作经历',
  `certificate_reward` text COMMENT '证书奖励',
  `self_assessment` text COMMENT '自我评价',
  `tag_me` varchar(255) DEFAULT '' COMMENT '自评标签',
  `jxjh` text COMMENT '教学计划',
  `age` int(10) DEFAULT NULL COMMENT '年龄',
  `work_time` varchar(100) DEFAULT '' COMMENT '工作经营时长',
  `education_background` varchar(255) DEFAULT '' COMMENT '最高学历',
  `is_premium` int(10) DEFAULT '0' COMMENT '是否精品 0否 1是',
  `birthday` varchar(255) DEFAULT '' COMMENT '生日',
  `word_file` varchar(255) DEFAULT '' COMMENT '文档地址',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8mb4 COMMENT='身份信息表';";
    

    

    // 表名
    protected $name = 'identity_info';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    /**
     * 获取精品状态列表
     * @return array
     */
    public function getIsPremiumList()
    {
        return ['0' => __('否'), '1' => __('是')];
    }

    public static function xl(){
        $education_background = ['小学','初中','高中','中专','大专','本科','硕士','博士'];
        return $education_background;
    }

    public function getWeekNameArrList(){
        return [
            [
                'id'=>'周一',
                'name'=>'周一'
            ],[
                'id'=>'周二',
                'name'=>'周二'
            ],[
                'id'=>'周三',
                'name'=>'周三'
            ],[
                'id'=>'周四',
                'name'=>'周四'
            ],[
                'id'=>'周五',
                'name'=>'周五'
            ],[
                'id'=>'周六',
                'name'=>'周六'
            ],[
                'id'=>'周天',
                'name'=>'周天'
            ]
        ];
    }

    public function getWeekList(){
        return [
            1=>'周一',
            2=>'周二',
            3=>'周三',
            4=>'周四',
            5=>'周五',
            6=>'周六',
            7=>'周天'
        ];
    }
    public function getWeekNameList(){
        return [
            '周一'=>1,
            '周二'=>2,
            '周三'=>3,
            '周四'=>4,
            '周五'=>5,
            '周六'=>6,
            '周天'=>7,
            '周日'=>7,
            '周七'=>7
        ];
    }
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id', [], 'LEFT')->field('id,avatar,mobile,username,nickname');
    }

    public function clubDtl(){
        return $this->hasOne(ClubDtl::class,'id','club_two_id', [], 'LEFT')->setEagerlyType(0);
    }

    public function club(){
        return $this->hasOne(Club::class,'id','club_one_id', [], 'LEFT')->setEagerlyType(0);
    }

    public function clubDtlS(){
        return $this->hasOne(ClubDtl::class,'id','club_two_id', [], 'LEFT')->field('id,name,stage,grade');
    }

    public function teacherDetail(){
        return $this->hasMany(TeacherDetail::class,'info_id','id')->with(['clubDtlS']);
    }
    public function teacherDetailJp(){
        return $this->hasMany(TeacherDetail::class,'info_id','id')->where(['is_premium'=>1])->with(['clubDtlS']);
    }

    //默认添加
    public function default_add($phone,$user_id,$identity_type='教师'){
        $info = $this->where(['phone'=>$phone])->find();
        $save = [];
        if(!$info){
            $data = [];
            $data['user_id'] = $user_id;
            $data['identity_type'] = $identity_type;
            $user = User::where(['id'=>$user_id])->find();
            $data['name'] = $user['nickname'];
            $data['phone'] = $phone;
            $data['sort'] = 1;
            $data['addtime'] = date('Y-m-d H:i:s');
            $save = $this->insert($data);
        }
        return $save;
    }

    public static function up_week($teacher_id){
        $ky_week = TeacherSubscribe::where(['teacher_id'=>$teacher_id,'class_id'=>0])->column('week');
        $identity_info_model = new \app\admin\model\IdentityInfo();
        $getWeekList = $identity_info_model->getWeekList();
        $week_name_arrs = [];
        foreach ($ky_week as $k=>$v){
            $week_name_arrs[$k] = isset($getWeekList[$v]) ? $getWeekList[$v] : '';
        }
        $week_name = implode(',',$week_name_arrs);
        IdentityInfo::where(['user_id'=>$teacher_id,'identity_type'=>'教师'])->update(['appointment_time_week'=>$week_name]);
        return true;
    }

}
